package com.ykt.controller;

import java.util.List;

import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.ykt.model.ShopCategory;

@ControllerBind(controllerKey="/shopCategory")
public class ShopCategoryController extends BaseController<ShopCategory> {

	public ShopCategoryController() {
		super(ShopCategory.class);
	}
	
	/***AJAX  查找某一市场下的商铺分类***/
	public void findMarketCategory() {
        int id = getParaToInt(0, 0);

        List<ShopCategory> list = null;
        String sql = "SELECT * FROM shop_category ";
        
        if (id == 0) list = ShopCategory.dao.find(sql);
        else list = ShopCategory.dao.find(sql + " where market_id =?", id);

        if(list.size()>0){
			this.rendJson(true, "查询成功", list);
		}else{
			this.rendJson(false, "没有相关分类", "");
		}
    }
	
	/***查找某一市场下的分类***/
	public void comboboxMarketCategory() {
        int id = getParaToInt(0, 0);

        List<Record> list = null;
        String sql = "SELECT * FROM shop_category ";
        
        if (id == 0) list = Db.find(sql);
        else list = Db.find(sql + " where market_id =?", id);

        this.renderJson(list);
    }
	
	/***原查找某一市场下的分类bak***/
	public void comboboxMarket() {
        int id = getParaToInt(0, 0);

        List<Record> list = null;
        String sql = "SELECT c.* FROM category c LEFT JOIN market_category m ON c.id = m.category_id WHERE m.market_id = " + id;
        list = Db.find(sql);

        this.renderJson(list);
    }
	
}
